const { notEmpty } = require('../utils.js')

module.exports = {
    description: 'generate store',
    prompts: [{
            type: 'input',
            name: 'name',
            message: 'store name please',
            validate: notEmpty('name')
        },
        {
            type: 'checkbox',
            name: 'blocks',
            message: 'Blocks:',
            choices: [{
                name: 'state',
                value: 'state',
                checked: true
            }],
            validate(value) {
                if (!value.includes('state')) {
                    return 'store require at least state and mutations'
                }
                return true
            }
        }
    ],
    actions(data) {
        const name = '{{name}}'
        const { blocks } = data
        const options = ['state']
        const joinFlag = `,
  `
        if (blocks.length === 3) {
            options.push('actions')
        }

        const actions = [{
            type: 'add',
            path: `./src/options/${name}-options.js`,
            templateFile: 'plop-templates/options/index.js',
            data: {
                state: blocks.includes('state'),
            }
        }]
        return actions
    }
}
